﻿using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using QuanLyKhachSan;

namespace UnitTest
{
    public class clsTestHoaDon:clsTest
    {

        [Test]
        public void TestInsert()
        {
            //su dung he thong en-US
            System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

            HoaDonDTO hd = new HoaDonDTO();
            hd.MaKhachHang = 1;
            hd.NgayLapHoaDon = DateTime.Now;
            hd.TongTien = 150000;
            bool kq = HoaDonDAO.Insert(hd);

            Dictionary<string, object> para = new Dictionary<string, object>();
            para.Add("ngayLapHoaDon", hd.NgayLapHoaDon);
            para.Add("tongTien", hd.TongTien);//
            para.Add("maKhachHang", hd.MaKhachHang);

            expectedData = select_DataTable("HoaDon", para);
            if (expectedData.Rows.Count == 0)
            {
                Assert.IsFalse(kq);
            }
            else
            {
                Assert.GreaterOrEqual(expectedData.Rows.Count, 1, "Cần Insert xuống CSDL");
                Assert.IsTrue(kq);
                Assert.AreEqual((DateTime.Parse( expectedData.Rows[0]["ngayLapHoaDon"].ToString())).ToShortDateString(), hd.NgayLapHoaDon.ToShortDateString(), "ngayLapHoaDon not the same");
                Assert.AreEqual(float.Parse(expectedData.Rows[0]["tongTien"].ToString()), hd.TongTien, "tongTien not the same");
                Assert.AreEqual(int.Parse(expectedData.Rows[0]["maKhachHang"].ToString()), hd.MaKhachHang, "maKhachhang not the same");

            }

            System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
        }
    }
}
